//
//  DYGroupSettingsContentCell.m
//  DaYing
//
//  Created by DaYing Team on 2023.
//  Copyright © 2023 DaYing Team. All rights reserved.
//

#import "DYGroupSettingsContentCell.h"

@implementation DYGroupSettingsContentCell

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
}

- (void)setData:(id)data delegate:(id)delegate {

    if ([data isKindOfClass:[NSDictionary class]]) {
        if ([data[@"data"] isKindOfClass:[DYGroupSettingsContentCellModel class]]) {
            DYGroupSettingsContentCellModel *model = data[@"data"];

            _titleLabel.text = model.title;

            if (model.position == 0) {
                _viewTop.constant = 0;
                _viewBottom.constant = -15;
                _lineLabel.hidden = NO;
            } else if (model.position == 1) {
                _viewTop.constant = -15;
                _viewBottom.constant = -15;
                _lineLabel.hidden = NO;
            } else if (model.position == 2) {
                _viewTop.constant = -15;
                _viewBottom.constant = 0;
                _lineLabel.hidden = YES;
            } else if (model.position == 3) {
                _viewTop.constant = 0;
                _viewBottom.constant = 0;
                _lineLabel.hidden = YES;
            }
        }
    }
}

+ (float)getCellFrame:(id)msg {
    
    if ([msg isKindOfClass:[DYGroupSettingsContentCellModel class]]) {
        DYGroupSettingsContentCellModel *model = msg;

        CGSize titleSize = [model.title ex_sizeWithFont:[UIFont boldSystemFontOfSize:16] constrainedToSize:CGSizeMake(kScreenWidth - 70, MAXFLOAT)];
        
        return 60 + titleSize.height - 19;
    }
    
    return 60;
}

@end


#pragma mark - Model

@implementation DYGroupSettingsContentCellModel

+ (DYGroupSettingsContentCellModel *)ittemModelWithTitle:(NSString *)title position:(NSInteger)position {
    DYGroupSettingsContentCellModel *model = [DYGroupSettingsContentCellModel new];
    model.title = title.length > 0 ? title : @"";
    model.position = position;
    return model;
}

@end
